home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group01b.txt
/
000134_icon-group-sender_Tue Aug 7 16:45:42 2001.msg
< prev
next >
Wrap
Internet Message Format
|
2002-01-03
|
2KB
Return-Path: <icon-group-sender>
Received: (from root@localhost)
by baskerville.CS.Arizona.EDU (8.11.1/8.11.1) id f77NhlE26494
for icon-group-addresses; Tue, 7 Aug 2001 16:43:47 -0700 (MST)
Message-Id: <200108072343.f77NhlE26494@baskerville.CS.Arizona.EDU>
Date: Tue, 07 Aug 2001 15:20:43 -0700
From: Steve Wampler <swampler@noao.edu>
X-Accept-Language: en
To: icon-group@cs.arizona.edu
Subject: Re: Sorting
Errors-To: icon-group-errors@cs.arizona.edu
Status: RO
Content-Length: 1688
Anders Holtsberg wrote:
>
> What is the simplest way to sort a list of records according to
> one of the fields? It seems hat this is not a one liner, or is
> it? My quick hack is this:
>
> procedure sortbyfield(thelist, i)
> t := table(&null)
> every e := !thelist do t[e[i]] := e;
> s := sort(t, 1)
> w := []
> every put(w, (!s)[2])
> return w
> end
Seems like a reasonable approach to me. Of course, it does
assume that all the elements in the list are subscriptable
[and imagine what happens if there are some strings stuck in there!].
Of course, since you (as the programmer) know the list contains
only records it should work quite nicely.
> For tables one can give a second argument to the sort procedure,
> but for lists the second argument is simply ignored.
>
> One simple for future enhancement to Icon is to use the above
> semantics for a two argument call to sort, where the first
> argument is either a list of records or a list of lists. Even
> better is to also accept a string as second argument for the
> case that the first argument is a list of records. Is this
> sensible?
I think it's an interesting idea, but probably needs some more
work on the details. Since there is no concept of a homogeneous
list in Icon, there need to be clearly defined rules on how to
sort elements that don't contain anything matching the sort
field index - generating a runtime error as the above code
does is probably not acceptable in the general case.
If you're going to add this to sort for sorting lists, it might be
good to also add it to sort for sorting tables as well!
--
Steve Wampler- SOLIS Project, National Solar Observatory
swampler@noao.edu